<template>
	<view class="container">
		<view class="product-list flex-space-between flex-wrap">
			<view class="product-item bg-fff" v-for="(item,index) in productList" :key="index" @click="toDetail(item)">
				<image class="product-item-image" :src="item.product.image[0].file_path"></image>
				<view class="product-con">
					<view class="product-con-name u-line-2">{{item.product.product_name}}</view>
					<view class="flex-space-between">
						<view class="product-con-price"><text>￥</text>{{item.product.product_price}}</view>
						<b-u-button-theme width="52rpx" height="40rpx" size="24rpx" @click="toDetail(item)">购买</b-u-button-theme>
					</view>
				</view>
			</view>
			
			<view class="product-item" v-if="productList.length % 2 == 1"></view>
		</view>
		
		<view v-if="productList.length > 0">
			<b-u-loadmore :status="loadmoreStatus"></b-u-loadmore>
		</view>
		<view v-else style="padding-top: 100rpx;">
			<u-empty text="暂无数据" mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageForm: {
					brand_id: '',
					page: 1,
					list_rows: 20,
				},
				productList: [],
				loadmoreStatus: 'nomore',
			}
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: options.brand_name
			})
			this.pageForm.brand_id = options.brand_id;
			this.getHttp();
		},
		onReachBottom() {
			if(this.loadmoreStatus == 'nomore') {
				return;
			}
			this.pageForm.page++;
			this.getBrandProduct();
		},
		methods: {
			toDetail(item){
				// console.log('item',item)
				if(item.categorydetail.type==1){
					this.jump('/pages/categoty/product/product_no_cart?id='+item.product_id)
				}else{
					this.jump('/pages/categoty/product/product?id='+item.product_id)
				}
			},
			jump(url) {
				uni.navigateTo({
					url: url
				})
			},
			getBrandProduct() {
				this.loadmoreStatus = 'loading';
				uni.$u.api.getBrandProduct(this.pageForm).then(res => {
					this.productList = this.productList.concat(res.list.data);
					this.loadmoreStatus = 'loadmore';
					if(this.productList.length  == res.list.total) {
						this.loadmoreStatus = 'nomore';
					}
				})
			},
			getHttp() {
				this.getBrandProduct();
			},
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 30rpx;
		
		.product-list {
			
			.product-item {
				width: 334rpx;
				border-radius: 16rpx;
				margin-bottom: 24rpx;
				overflow: hidden;
			}
			
			.product-item-image {
				width: 334rpx;
				height: 328rpx;
			}
			
			.product-con {
				padding: 12rpx 20rpx 18rpx;
				
				.product-con-name {
					font-size: 26rpx;
					color: #111111;
					font-weight: bold;
					margin-bottom: 14rpx;
					min-height: 68rpx;
				}
				
				.product-con-price {
					font-size: 36rpx;
					font-weight: bold;
					color: $uni-color-theme;
					
					text {
						font-size: 24rpx;
					}
				}
			}
		}
	}
</style>
